package com.demoworld;

import com.demoworld.tasks.RunnableTask;
import com.demoworld.tasks.ThreadTask;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by francis on 2017/12/11.
 */
public class Startup {
    public static void main(String[] args) {
        test3();
    }

    public static void test3() {
        Callable<Integer> callable = new Callable<Integer>() {
            public Integer call() throws Exception {
                return new Random().nextInt(100);
            }
        };
        FutureTask<Integer> future = new FutureTask<Integer>(callable);
        new Thread(future).start();
        try {
            Thread.sleep(5000);// 可能做一些事情
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    public static void test2() {
        ThreadTask threadTask = new ThreadTask();
        threadTask.setDaemon(false);
        threadTask.start();
    }

    public static void test1() {
        Thread thread = new Thread(new RunnableTask());
        thread.setDaemon(false);
        thread.start();

        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
